package com.glory.brepda.activity.mfg;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.glory.brepda.R;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.BomEntity;
import com.glory.brepda.entity.LotInfoEntity;
import com.glory.brepda.entity.SuspendCodeBean;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.LotUtils;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralPop;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_PopUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class MaterialReservedActivity extends BaseActivity {

    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.etLotID)
    FreeUI_ClearEditText etLotID;
    @BindView(R.id.etType)
    FreeUI_ClearEditText etType;
    @BindView(R.id.tvQty)
    TextView tvQty;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_release;
    }

    @Override
    protected void initView() {

        String title = getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY);
        tvBaseSubmit.setText("提交");
        tvTitle.setText(title);
        setMainLayout(llMain);

    }

    @Override
    protected void initData() {

        initEdit(etLotID,s ->{
            FreeUI_EntityCallBack<BaseResponseBean<LotInfoEntity>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<LotInfoEntity>>
                    ("正在查询LOT信息", new TypeToken<BaseResponseBean<LotInfoEntity>>() {
                    }.getType(), getSupportFragmentManager(), MaterialReservedActivity.this) {

                @Override
                public void onSuccess(Response<BaseResponseBean<LotInfoEntity>> response) {
                    super.onSuccess(response);
                    if (response.body().isSuccess(MaterialReservedActivity.this, true, getSupportFragmentManager())) {
                        tvQty.setText(response.body().getResponse().getBody().getXMLot().getMAINQTY());
                        etType.setText(response.body().getResponse().getBody().getXMLot().getMATERIALTYPE());
                    }

                }

                @Override
                public void onError(Response<BaseResponseBean<LotInfoEntity>> response) {
                    super.onError(response);
                    loadError(response.getException(), "LOTQUERY");
                }
            };

            JsonObject map = new JsonObject();
            map.addProperty("ACTIONTYPE", "QUERYBYID");
            map.addProperty("MLOTID", s);
            NetUtils.requestPostNet("IF.FINDMLOTBYID", "Common", MaterialReservedActivity.this, map, callBack);
        });

    }

    @OnClick({R.id.tvBaseSubmit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvBaseSubmit:
                FreeUI_EntityCallBack<BaseResponseBean<BomEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseResponseBean<BomEntity>>
                        (new TypeToken<BaseResponseBean<BomEntity>>() {
                        }.getType(), getSupportFragmentManager(), this) {

                    @Override
                    public void onSuccess(Response<BaseResponseBean<BomEntity>> response) {
                        super.onSuccess(response);
                        if (response.body().isSuccess(getApplicationContext(),true,getSupportFragmentManager())){
                            showToast("物料暂停成功",true);
                        }
                    }

                    @Override
                    public void onError(Response<BaseResponseBean<BomEntity>> response) {
                        super.onError(response);
                        loadError(response.getException(),"MLOTHOLD");
                    }
                };

                JsonObject map = new JsonObject();
                map.addProperty("ACTIONTYPE","HOLD");
                map.addProperty("MLOTID",getText(etLotID));
                NetUtils.requestPostNet("IF.MLOTHOLD","Common", MaterialReservedActivity.this,map,callBack);

                break;
        }
    }
}
